{
  "properties" : { },
  "id" : "47ea53dbb25246b5838a86fc46b718d5",
  "script" : null,
  "groupId" : "589e96db1e864e6a9a1bedd3d9e05cd1",
  "name" : "消息发送测试",
  "createTime" : null,
  "updateTime" : 1741279399802,
  "lock" : null,
  "createBy" : null,
  "updateBy" : "管理员",
  "path" : "mqtest",
  "method" : "GET",
  "parameters" : [ ],
  "options" : [ ],
  "requestBody" : "",
  "headers" : [ ],
  "paths" : [ ],
  "responseBody" : "{\n    \"code\": 200,\n    \"msg\": \"success\",\n    \"data\": 0\n}",
  "description" : null,
  "requestBodyDefinition" : null,
  "responseBodyDefinition" : null
}
================================
import com.alibaba.fastjson.JSONObject
import java.util.Random;
import log;

import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.MqttPersistenceException;
import org.eclipse.paho.client.mqttv3.MqttTopic;
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;

    //
    var mqUrl = 'tcp://127.0.0.1:1883'
    var mqUsername = 'user2'
    var mqPassword = 'get3efe$#gssd'

    var msgPage = "topic_zjt"
    var content = {
        "name": "户外监控",
        "type": "m3u8", "id": "10001",
        "ffmpeg_home": "D:/opt/ffmpeg/bin",
        "rtsp": "rtsp://admin:huishao2045@192.168.0.51:554/stream1",
        "code": "-c:a copy -c:v libx264 -preset:v fast -tune:v zerolatency -max_delay 50",
        "flv": "flv -s 640x360 -g 5 -b 1600k",
        "rtmp": "rtmp://127.0.0.1:18083/video/"
    };
    var mqMsg = JSONObject.toJSONString(content);

    MqttClient client = new MqttClient(mqUrl, 'msb-'+new Random().nextInt(), new MemoryPersistence()); 
    MqttConnectOptions options = new MqttConnectOptions();
    MqttMessage msg = new MqttMessage();
    try {
        options.setUserName(mqUsername);
        options.setPassword(mqPassword.toCharArray());
        options.setCleanSession(true);
        // 连接
        client.connect(options);

        // 发送并等待完成
        msg.setPayload(mqMsg.getBytes());
        client.getTopic(msgPage).publish(msg).waitForCompletion();

        // 关闭
        client.disconnect()
        client.close();
    } catch(e) {
        return e.getMessage()
    }

return 0;